<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>检查某个名称的常量是否存在</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.defined" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">defined</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">defined</span> &mdash; <span class="dc-title">检查某个名称的常量是否存在</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.defined-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>defined</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$name</code></span>
   ) : <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   检查该名称的常量是否已定义。
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    如果你要检查一个变量是否存在，请使用 <span class="function"><a href="isset.html" class="function">isset()</a></span>。
      <span class="function"><strong>defined()</strong></span> 函数仅对 <a href="language.constants.html" class="link">constants</a> 有效。如果你要检测某个函数是否存在，使用 <span class="function"><a href="function_exists.html" class="function">function_exists()</a></span>。
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.defined-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">name</code></dt>

     <dd>

      <p class="para">
       常量的名称。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.defined-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
  如果名称 <code class="parameter">name</code> 的常量已定义，返回 <strong><code>TRUE</code></strong>；未定义则返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.defined-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4533">
    <p><strong>Example #1 检查常量</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Note&nbsp;the&nbsp;use&nbsp;of&nbsp;quotes,&nbsp;this&nbsp;is&nbsp;important.&nbsp;&nbsp;This&nbsp;example&nbsp;is&nbsp;checking<br />&nbsp;*&nbsp;if&nbsp;the&nbsp;string&nbsp;'TEST'&nbsp;is&nbsp;the&nbsp;name&nbsp;of&nbsp;a&nbsp;constant&nbsp;named&nbsp;TEST&nbsp;*/<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">defined</span><span style="color: #007700">(</span><span style="color: #DD0000">'TEST'</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">TEST</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.defined-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="define.html" class="function" rel="rdfs-seeAlso">define()</a> - 定义一个常量</span></li>
    <li class="member"><span class="function"><a href="constant.html" class="function" rel="rdfs-seeAlso">constant()</a> - 返回一个常量的值</span></li>
    <li class="member"><span class="function"><a href="get_defined_constants.html" class="function" rel="rdfs-seeAlso">get_defined_constants()</a> - 返回所有常量的关联数组，键是常量名，值是常量值</span></li>
    <li class="member"><span class="function"><a href="function_exists.html" class="function" rel="rdfs-seeAlso">function_exists()</a> - 如果给定的函数已经被定义就返回 TRUE</span></li>
    <li class="member">章节 <a href="language.constants.html" class="link">Constants</a></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>